{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "70acda81",
   "metadata": {},
   "source": [
    "# 1.列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05e3c3f5",
   "metadata": {},
   "source": [
    "* 思考：如果我们班同学的名字都存起来，你会怎么做？用变量name1、name2、name3...来存么？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2f893fba",
   "metadata": {},
   "outputs": [],
   "source": [
    "name1=\"张三\"\n",
    "name2=\"梨花\"\n",
    "name3=\"李鹏\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6faef368",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d7a2e912",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'梨花'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "77fe9f5e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'李鹏'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a5568241",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"张三，梨花，李鹏，李晓明\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "44cb8aa3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三，梨花，李鹏，李晓明'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "56cd0f3c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0d8e8def",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'梨花'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name[3:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3eaec64f",
   "metadata": {},
   "source": [
    "* 综上，新的数据结构产生"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "76e3feef",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list =[\"张三\",\"梨花\",\"李鹏\",\"李晓明\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1bcc0ec4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '梨花', '李鹏', '李晓明']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9fbc2fec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6068629e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'梨花'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7126242b",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_学号 = [2210510049,2210510050,2210510051]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0dd7c325",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2210510049, 2210510050, 2210510051]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_学号"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b1111cc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_list[1] = \"李树人\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "11589757",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', '李树人', '李鹏', '李晓明']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "ec6e2df2",
   "metadata": {},
   "outputs": [],
   "source": [
    "name_张三 = [\"张三\",221050114,18,180,75,\"Jack\",[\"Python\",\"移动互联网\",\"UI设计\"]]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "86766d35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['张三', 221050114, 18, 180, 75, 'Jack', ['Python', '移动互联网', 'UI设计']]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name_张三 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6179b25b",
   "metadata": {},
   "source": [
    "* 列表可以存放不同类型的数据，但是一半存放的数据都是同一种类型\n",
    "* 官网原话：lists might contain items of different types,but usually the items all have the same type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b1bb1796",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 允许重复的数据**(数据重复性)**\n",
    "网三_python成绩 = [95,97,94,95,97]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4fda28f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[95, 97, 94, 95, 97]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_python成绩"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c789738",
   "metadata": {},
   "source": [
    "# 1.2 创建列表\n",
    "\n",
    ">1. 使用list()创建列表\n",
    ">2. 使用[]创建列表，中间的元素用**英文的**，隔开\n",
    ">3. 创建一个空列表,方法也是上面两种"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "af995e07",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[18, 19, 18, 20]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 1.使用list()创建列表\n",
    "my_list1 = list((18,19,18,20))\n",
    "my_list1\n",
    "print(my_list1)\n",
    "print(type(my_list1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "69abdc7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[75, 80, 75, 74]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 2. 用[]创建列表，中间的元素用**英文的**，隔开\n",
    "my_list2 = [75,80,75,74]\n",
    "print(my_list2)\n",
    "print(type(my_list2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6787bfc",
   "metadata": {},
   "source": [
    "* 特殊小案例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5172134d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['p', 'y', 't', 'h', 'o', 'n']\n"
     ]
    }
   ],
   "source": [
    "my_list3 = list(\"python\")\n",
    "print(my_list3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "fb57f963",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['H', 'e', 'l', 'l', 'o', ' ', 'l', 'i', 's', 't', '~']\n"
     ]
    }
   ],
   "source": [
    "my_list4 = list(\"Hello list~\")\n",
    "print(my_list4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "055128f5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 3. 创建空列表\n",
    "empty_list = list()\n",
    "print(empty_list)\n",
    "print(type(empty_list))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79e35236",
   "metadata": {},
   "source": [
    "## 1.3 查看列表的长度 : len()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "11c34571",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(my_list4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77dc5cde",
   "metadata": {},
   "source": [
    "## 1.4 列表的取值和切片\n",
    "* index:取值\n",
    "* slice:切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "b4f6668b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['p', 'y', 't', 'h', 'o', 'n']"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_list = list(\"python\")\n",
    "python_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "360f9ada",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'p'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "python_list[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e86e1c74",
   "metadata": {},
   "source": [
    "# 1.5 列表的一般方法\n",
    "* 笔记:数据如何处理是很重要的事\n",
    "* 数据的基本操作流程:\n",
    "> 1. 增加 add\n",
    "> 2. 减少/删除 remove\n",
    "> 3. 查询 find\n",
    "> 4. 修改 update"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b120b4ab",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
